/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * MaestroAlmacen.java
 *
 * Created on 21/06/2012, 12:12:01 AM
 */
package com.camachosanchez.gui;

import com.camachosanchez.bean.Almacenes;
import com.camachosanchez.controler.jdbc.AlmacenesJdbcControler;
import com.camachosanchez.controler.jpa.AlmacenesJpaController;
import com.camachosanchez.gui.textfield.MaxLengthTextDocument;
import com.camachosanchez.util.Constantes;
import com.camachosanchez.util.EstadosJDialog.EstadoJDialog;
import com.camachosanchez.util.GUIUtil;
import java.awt.event.KeyEvent;
import javax.swing.JOptionPane;

/**
 *
 * @author Zully
 */
public class EditorAlmacen extends javax.swing.JDialog {

    /** Creates new form MaestroAlmacen */
    public EstadoJDialog Estado;
    private MaestroAlmacenes buscador;
    private int fila;
    private Almacenes almacen;

    public EditorAlmacen(MaestroAlmacenes buscador, java.awt.Frame parent, boolean modal, Almacenes almacen, int fila) {
        super(parent, modal);
        initComponents();
        this.setLocationRelativeTo(null);
        GUIUtil.addEscapeKey(this);
        this.buscador = buscador;
        this.fila = fila;
        
        MaxLengthTextDocument docTelefono = new MaxLengthTextDocument();
        MaxLengthTextDocument docFax = new MaxLengthTextDocument();
        MaxLengthTextDocument docEmail = new MaxLengthTextDocument();
        docTelefono.setMaxChars(15, Constantes.ANY);
        docFax.setMaxChars(15, Constantes.ANY);
        docEmail.setMaxChars(30, Constantes.ANY);
        txtTelefono.setDocument(docTelefono);
        txtFax.setDocument(docFax);
        txtEmail.setDocument(docEmail);
        txtNombre.requestFocusInWindow();
        
        if (almacen != null) {
            this.CargarDatosAlmacen(almacen);
            this.almacen = almacen;
        }
    }

    public EstadoJDialog getEstado() {
        return Estado;
    }

    public void setEstado(EstadoJDialog Estado) {
        switch (Estado) {
            case NUEVO:
                btnEliminar.setVisible(false);
//                jSeparator2.setVisible(false);
                break;
            case MODIFICAR:
                btnEliminar.setVisible(true);
//                jSeparator2.setVisible(true);
                break;
        }
        this.Estado = Estado;
    }

    private void GuardarDatos() {
        switch (this.Estado) {
            case NUEVO:
                this.RegistrarAlmacen(this.LeerDatosAlmacen());
                break;
            case MODIFICAR:
                this.ModificarAlmacen(this.LeerDatosAlmacen());
                break;
            case ELIMINAR:
                break;
            default:
                break;
        }
    }

    private void CargarDatosAlmacen(Almacenes almacen) {
//        this.jTxtCodigo.setInformacionUsuario("" + almacen.getId());
        txtNombre.setText(almacen.getNombre());
        txtDireccion.setText(almacen.getDireccion());
        txtTelefono.setText(almacen.getTelefono());
        txtFax.setText(almacen.getFax());
        txtEmail.setText(almacen.getEmail());
        txtEncargado.setText(almacen.getEncargado());
        txpComentarios.setText(almacen.getComentarios());
//        this.jCheckEstado.setSelected(almacen.isEstado());
    }

    private Almacenes LeerDatosAlmacen() {
        Almacenes a = new Almacenes();
//        a.setId((this.jTxtCodigo.getText().compareTo("") != 0) ? Integer.parseInt(this.jTxtCodigo.getText()) : 0);
        a.setNombre(txtNombre.getText().trim());
        a.setDireccion(txtDireccion.getText().trim());
        a.setTelefono(txtTelefono.getText().trim());
        a.setFax(txtFax.getText().trim());
        a.setEmail(txtEmail.getText().trim());
        a.setEncargado(txtEncargado.getText().trim());
        a.setComentarios(txpComentarios.getText());
//        a.setEstado(this.jCheckEstado.isSelected());
        if (this.almacen != null) {
            a.setNeumaticosList(this.almacen.getNeumaticosList());
        }
        return a;
    }

    private boolean ValidarDatos() {
        if (txtNombre.getText().isEmpty()) {
            JOptionPane.showMessageDialog(this, "Se requiere un nombre para el almacén.", "Datos incompletos", JOptionPane.WARNING_MESSAGE);
            txtNombre.requestFocusInWindow();
            return false;
        }
        return true;
    }

    private void RegistrarAlmacen(Almacenes almacen) {
        AlmacenesJpaController dao_almacen = new AlmacenesJpaController(null);
        almacen.setEstado(true);
        dao_almacen.create(almacen);
        JOptionPane.showMessageDialog(this, "El almacén ha sido guardado correctamente.", "Operación finalizada", JOptionPane.INFORMATION_MESSAGE);
        buscador.llenarAlmacenes();
        this.dispose();
    }

    private void ModificarAlmacen(Almacenes almacen) {
        AlmacenesJpaController dao_almacen = new AlmacenesJpaController(null);
        try {
            almacen.setEstado(true);
            almacen.setId(this.almacen.getId());
            dao_almacen.edit(almacen);
            JOptionPane.showMessageDialog(this, "Los datos del almacén han sido actualizados correctamente.", "Operación finalizada", JOptionPane.INFORMATION_MESSAGE);
            buscador.llenarAlmacenes();
            dispose();
        } catch (Exception e) {
            JOptionPane.showMessageDialog(Principal.getInstance(), e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        toolBarPrincipal = new javax.swing.JToolBar();
        pnlToolBar = new javax.swing.JPanel();
        btnGuardar = new javax.swing.JButton();
        btnEliminar = new javax.swing.JButton();
        pnlContenedor = new javax.swing.JPanel();
        lblNombre = new javax.swing.JLabel();
        txtNombre = new javax.swing.JTextField();
        lblDireccion = new javax.swing.JLabel();
        txtDireccion = new javax.swing.JTextField();
        lblTelefono = new javax.swing.JLabel();
        txtTelefono = new javax.swing.JTextField();
        lblFax = new javax.swing.JLabel();
        txtFax = new javax.swing.JTextField();
        lblEmail = new javax.swing.JLabel();
        txtEmail = new javax.swing.JTextField();
        lblEncargado = new javax.swing.JLabel();
        txtEncargado = new javax.swing.JTextField();
        tbpComentarios = new javax.swing.JTabbedPane();
        pnlComentarios = new javax.swing.JPanel();
        scrComentarios = new javax.swing.JScrollPane();
        txpComentarios = new javax.swing.JTextPane();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle(".:: Almacén ::.");
        setResizable(false);

        toolBarPrincipal.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        toolBarPrincipal.setFloatable(false);
        toolBarPrincipal.setRollover(true);
        toolBarPrincipal.setOpaque(false);

        pnlToolBar.setBackground(new java.awt.Color(255, 255, 255));
        pnlToolBar.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEFT));

        btnGuardar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/camachosanchez/recursos/24_save.png"))); // NOI18N
        btnGuardar.setToolTipText("Guardar");
        btnGuardar.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        btnGuardar.setFocusable(false);
        btnGuardar.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        btnGuardar.setMaximumSize(new java.awt.Dimension(22, 22));
        btnGuardar.setMinimumSize(new java.awt.Dimension(22, 22));
        btnGuardar.setPreferredSize(new java.awt.Dimension(22, 22));
        btnGuardar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnGuardar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGuardarActionPerformed(evt);
            }
        });
        pnlToolBar.add(btnGuardar);

        btnEliminar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/camachosanchez/recursos/24_delete.png"))); // NOI18N
        btnEliminar.setToolTipText("Eliminar");
        btnEliminar.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        btnEliminar.setFocusable(false);
        btnEliminar.setHorizontalTextPosition(javax.swing.SwingConstants.RIGHT);
        btnEliminar.setMaximumSize(new java.awt.Dimension(22, 22));
        btnEliminar.setMinimumSize(new java.awt.Dimension(22, 22));
        btnEliminar.setPreferredSize(new java.awt.Dimension(22, 22));
        btnEliminar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnEliminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEliminarActionPerformed(evt);
            }
        });
        pnlToolBar.add(btnEliminar);

        toolBarPrincipal.add(pnlToolBar);

        getContentPane().add(toolBarPrincipal, java.awt.BorderLayout.PAGE_START);

        lblNombre.setText("<html>Nombre: <font color=\"red\">(*)</font> </html>");

        txtNombre.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtNombreKeyPressed(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtNombreKeyTyped(evt);
            }
        });

        lblDireccion.setText("Dirección:");

        txtDireccion.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtDireccionKeyPressed(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtDireccionKeyTyped(evt);
            }
        });

        lblTelefono.setText("Teléfono:");

        txtTelefono.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtTelefonoKeyPressed(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtTelefonoKeyTyped(evt);
            }
        });

        lblFax.setText("Fax:");

        txtFax.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtFaxKeyPressed(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtFaxKeyTyped(evt);
            }
        });

        lblEmail.setText("Em@il:");

        txtEmail.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtEmailKeyPressed(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtEmailKeyTyped(evt);
            }
        });

        lblEncargado.setText("Encargado:");

        txtEncargado.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                txtEncargadoKeyPressed(evt);
            }
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtEncargadoKeyTyped(evt);
            }
        });

        tbpComentarios.setBackground(new java.awt.Color(188, 211, 226));

        pnlComentarios.setLayout(new java.awt.BorderLayout());

        scrComentarios.setViewportView(txpComentarios);

        pnlComentarios.add(scrComentarios, java.awt.BorderLayout.CENTER);

        tbpComentarios.addTab("Comentarios", pnlComentarios);

        javax.swing.GroupLayout pnlContenedorLayout = new javax.swing.GroupLayout(pnlContenedor);
        pnlContenedor.setLayout(pnlContenedorLayout);
        pnlContenedorLayout.setHorizontalGroup(
            pnlContenedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlContenedorLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlContenedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(tbpComentarios, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 418, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, pnlContenedorLayout.createSequentialGroup()
                        .addComponent(lblNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(txtNombre, javax.swing.GroupLayout.DEFAULT_SIZE, 350, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, pnlContenedorLayout.createSequentialGroup()
                        .addComponent(lblEmail, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(txtEmail, javax.swing.GroupLayout.DEFAULT_SIZE, 136, Short.MAX_VALUE)
                        .addGap(214, 214, 214))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, pnlContenedorLayout.createSequentialGroup()
                        .addGroup(pnlContenedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblTelefono)
                            .addComponent(lblDireccion))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(pnlContenedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(pnlContenedorLayout.createSequentialGroup()
                                .addComponent(txtTelefono, javax.swing.GroupLayout.DEFAULT_SIZE, 136, Short.MAX_VALUE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(lblFax, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(txtFax, javax.swing.GroupLayout.PREFERRED_SIZE, 94, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(txtDireccion, javax.swing.GroupLayout.DEFAULT_SIZE, 350, Short.MAX_VALUE)))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, pnlContenedorLayout.createSequentialGroup()
                        .addComponent(lblEncargado, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(txtEncargado, javax.swing.GroupLayout.DEFAULT_SIZE, 350, Short.MAX_VALUE)))
                .addContainerGap())
        );

        pnlContenedorLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {lblDireccion, lblEmail, lblEncargado, lblFax, lblNombre, lblTelefono});

        pnlContenedorLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {txtEmail, txtFax, txtTelefono});

        pnlContenedorLayout.setVerticalGroup(
            pnlContenedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlContenedorLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlContenedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(pnlContenedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtDireccion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblDireccion))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(pnlContenedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblTelefono)
                    .addComponent(txtTelefono, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblFax)
                    .addComponent(txtFax, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(pnlContenedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblEmail)
                    .addComponent(txtEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(pnlContenedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblEncargado)
                    .addComponent(txtEncargado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(tbpComentarios, javax.swing.GroupLayout.DEFAULT_SIZE, 100, Short.MAX_VALUE)
                .addContainerGap())
        );

        getContentPane().add(pnlContenedor, java.awt.BorderLayout.CENTER);

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void btnGuardarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGuardarActionPerformed
// TODO add your handling code here:
    if (ValidarDatos()) {
        GuardarDatos();
    }
}//GEN-LAST:event_btnGuardarActionPerformed

private void txtNombreKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtNombreKeyPressed
// TODO add your handling code here:
    if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
        txtDireccion.requestFocusInWindow();
    }
}//GEN-LAST:event_txtNombreKeyPressed

private void txtDireccionKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtDireccionKeyPressed
// TODO add your handling code here:
    if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
        txtTelefono.requestFocusInWindow();
    }
}//GEN-LAST:event_txtDireccionKeyPressed

private void txtTelefonoKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtTelefonoKeyPressed
// TODO add your handling code here:
    if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
        txtFax.requestFocusInWindow();
    }
}//GEN-LAST:event_txtTelefonoKeyPressed

private void txtFaxKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtFaxKeyPressed
// TODO add your handling code here:
    if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
        txtEmail.requestFocusInWindow();
    }
}//GEN-LAST:event_txtFaxKeyPressed

private void txtEmailKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtEmailKeyPressed
// TODO add your handling code here:
    if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
        txtEncargado.requestFocusInWindow();
    }
}//GEN-LAST:event_txtEmailKeyPressed

private void txtEncargadoKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtEncargadoKeyPressed
// TODO add your handling code here:
    if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
        txpComentarios.requestFocusInWindow();
    }
}//GEN-LAST:event_txtEncargadoKeyPressed

    private void txtNombreKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtNombreKeyTyped
        // TODO add your handling code here:
//        char caracter = evt.getKeyChar();
        String caracteres = txtNombre.getText();
        if (caracteres.length() >= 45) {
            evt.consume();
        }
    }//GEN-LAST:event_txtNombreKeyTyped

    private void txtEncargadoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtEncargadoKeyTyped
        // TODO add your handling code here:
        char caracter = evt.getKeyChar();
        String caracteres = txtEncargado.getText();
        if ((!(Character.isLetter(caracter)) && (caracter != KeyEvent.VK_SPACE)) || (caracteres.length() >= 80)) {
            evt.consume();
        }
    }//GEN-LAST:event_txtEncargadoKeyTyped

    private void txtTelefonoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtTelefonoKeyTyped
        // TODO add your handling code here:
        String caracteres = txtTelefono.getText();
        if (caracteres.length() >= 15) {
            evt.consume();
        }
    }//GEN-LAST:event_txtTelefonoKeyTyped

    private void txtFaxKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtFaxKeyTyped
        // TODO add your handling code here:
        String caracteres = txtFax.getText();
        if (caracteres.length() >= 15) {
            evt.consume();
        }
    }//GEN-LAST:event_txtFaxKeyTyped

    private void txtEmailKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtEmailKeyTyped
        // TODO add your handling code here:
        String caracteres = txtEmail.getText();
        if (caracteres.length() >= 30) {
            evt.consume();
        }
    }//GEN-LAST:event_txtEmailKeyTyped

    private void btnEliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnEliminarActionPerformed
        // TODO add your handling code here:
        if (JOptionPane.showConfirmDialog(null, "¿Está seguro que desea eliminar este almacén?", "Confirmación", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
            AlmacenesJdbcControler daoJdbc = new AlmacenesJdbcControler();
            byte estado = daoJdbc.eliminarAlmacen(this.almacen.getId());
            if (estado == 1) {
                JOptionPane.showMessageDialog(this, "El almacén se encuentra relacionado con otros registros, no puede ser eliminado.", "Error en la eliminación", JOptionPane.ERROR_MESSAGE);
            } else {
                JOptionPane.showMessageDialog(this, "El almacén se ha eliminado de forma segura.", "Operación finalizada", JOptionPane.INFORMATION_MESSAGE);
                buscador.borrarAlmacen(fila);
                dispose();
            }
        }
    }//GEN-LAST:event_btnEliminarActionPerformed

    private void txtDireccionKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtDireccionKeyTyped
        // TODO add your handling code here:
        String caracteres = txtDireccion.getText();
        if (caracteres.length() >= 100) {
            evt.consume();
        }
    }//GEN-LAST:event_txtDireccionKeyTyped
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnEliminar;
    private javax.swing.JButton btnGuardar;
    private javax.swing.JLabel lblDireccion;
    private javax.swing.JLabel lblEmail;
    private javax.swing.JLabel lblEncargado;
    private javax.swing.JLabel lblFax;
    private javax.swing.JLabel lblNombre;
    private javax.swing.JLabel lblTelefono;
    private javax.swing.JPanel pnlComentarios;
    private javax.swing.JPanel pnlContenedor;
    private javax.swing.JPanel pnlToolBar;
    private javax.swing.JScrollPane scrComentarios;
    private javax.swing.JTabbedPane tbpComentarios;
    private javax.swing.JToolBar toolBarPrincipal;
    private javax.swing.JTextPane txpComentarios;
    private javax.swing.JTextField txtDireccion;
    private javax.swing.JTextField txtEmail;
    private javax.swing.JTextField txtEncargado;
    private javax.swing.JTextField txtFax;
    private javax.swing.JTextField txtNombre;
    private javax.swing.JTextField txtTelefono;
    // End of variables declaration//GEN-END:variables
}
